package testjson;

import com.alibaba.fastjson.JSONObject;
import org.junit.Test;

import java.io.Serializable;
import java.sql.SQLException;

public class phoenix  extends BaseDao implements Serializable {
    @Test
    public void JSONphoenix(String json) throws SQLException {
        System.out.println(json);
        MaxwellDto dto = JSONObject.parseObject(json, MaxwellDto.class);
        String database=dto.getDatabase();
        String tablename = dto.getTable();
        System.out.println("dto:"+dto);
        log.info("tablename" + tablename);
        log.info("type" + dto.getType());
        if (dto.getDatabase().equals("test_maxwell")&&dto.getType().equals("insert")) {
            IMDto im = JSONObject.parseObject(dto.getData(), IMDto.class);

            System.out.println("wwwwwwwwwwwwwww"+im);

            String rowid = rowkeys("abcdefg012345");
            String id;
            String name;

            id = im.getId();

            name = im.getName();
            if(id==null)
                id="null";
            if(name==null)
                name="null";
            try {

            //   String  table="create table hbase_ttt(s1 varchar not null primary key,s2 varchar,s3 varchar,s4 varchar)";
            String  sql="upsert into im values ('"+rowid+"','"+id+"','"+name+"')";
            System.out.println("jjjjjjjjjjjjjjjjjjjjj");
            //  PreparedStatement   pstmts= conn.prepareStatement(table);
            pstmt= conn.prepareStatement(sql);
            System.out.println("qqqqqqqqqqqqqqqqqqqqq");
            // boolean rss = pstmts.execute();
            boolean rs = pstmt.execute();
            conn.commit();

               } catch (SQLException e) {
                 e.printStackTrace(); // 处理SQLException异常
              } finally {
               try {
            closeAll(conn, pstmt, null);

             } catch (SQLException e) {
                    e.printStackTrace();
               }
              }
            System.out.println(id+ name + " is imported");


        }


    }









}
